home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / mouse.swg / 0009_Mouse Tutor.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-11-21  |  4.7 KB  |  142 lines

  1. {
  2. From: FRED JOHNSON
  3. Subj: Mousey Control..
  4. Can someone out there please explain how to read from the mouse?
  5. }
  6.  
  7. {Explanation below in reference table}
  8. USES dos,crt;
  9.  
  10. VAR
  11.  M1,M2,M3,M4 : word;
  12.  Regs        : Registers;  { MS DOS Registers }
  13.  satisfied   : boolean;    { if mouse pos and button are together }
  14.  
  15. PROCEDURE mouse( var M1,M2,M3,M4 : word );
  16.   begin
  17.     With Regs DO
  18.       begin
  19.         AX := M1; BX := M2; CX := M3; DX := M4;
  20.       end;
  21.     intr($33,Regs); { Interrupt $33, the mouse interrupt }
  22.     With Regs DO
  23.       begin
  24.         M1 := AX; M2 := BX; M3 := CX; M4 := DX;
  25.       end;
  26.   end;
  27.  
  28. PROCEDURE initmouse;
  29.   begin
  30.     M1 := 1 ; Mouse( M1,M2,M3,M4 ) { Set mouse cursor ON }
  31.   end;
  32.  
  33. BEGIN
  34.   satisfied := false;
  35.   textcolor(7); { Grey }
  36.   clrscr;
  37.   initmouse;
  38.  while not keypressed do { until  KEYBOARD key is pressed }
  39.     begin
  40.      M1 := 3;
  41.       MOUSE(m1,M2,M3,M4);
  42.       IF (M2 and 1) <> 0 then
  43.         begin                { if left button pressed }
  44.           writeln(' Left Button');
  45.           write(' M3 =',M3 div 8); write(' M4 =',M4 div 8);
  46.         end;
  47.       if (M2 and 2) <> 0 then
  48.         begin                { if rght button pressed }
  49.           writeln(' Right Button');
  50.           write(' M3 =',M3 div 8); write(' M4 =',M4 div 8);
  51.         end;
  52.       if (M2 and 4) <> 0 then                      {if midlbutton pressed}
  53.         begin
  54.           M1 := 4; M2 := 0; M3 := 30*8; M4 := 11*8; {Sets MCursor out of }
  55.           mouse( M1,M2,M3,M4 );                     {the way }
  56.           gotoxy(25,10); write('***************');
  57.           gotoxy(25,11); write('* ');textcolor(14);
  58.           write('C'); textcolor(07); write('learscreen *');
  59.           gotoxy(25,12); write('* '); textcolor(14);
  60.           write('Q'); textcolor(07); write('uit        *');
  61.           gotoxy(25,13); write('***************');
  62.           repeat
  63.             M1 := 3;
  64.             mouse(M1,M2,M3,M4);
  65.             if (M3 div 8) = 26 then                 { Tests X position }
  66.               if (M4 div 8) = 10 then               { Tests Y position }
  67.                 if (M2 and 1) <> 0 then             { Tests lft button }
  68.                   begin
  69.                     satisfied := true;
  70.                     M1 := 4; M2  := 0; M3 :=0; M4 :=0;{MCursor out of way}
  71.                     mouse( M1,M2,M3,M4 );
  72.                     clrscr;
  73.                   end;
  74.  
  75.             if (M3 div 8) = 26 then                { Tests X position }
  76.               if (M4 div 8) = 11 then              { Tests Y position }
  77.                 if (M2 and 1) <> 0 then            { Tests lft button }
  78.                   begin
  79.                     satisfied := true;
  80.                     M1 := 0; M2 :=0; M3 :=0; M4 := 0;  { Turn Mouse Off }
  81.                     mouse( M1,M2,M3,M4 );
  82.                     clrscr;
  83.                     halt;
  84.                   end;
  85.  
  86.           until satisfied = true;
  87.           clrscr;
  88.           end;
  89.           satisfied := false;
  90.    end;
  91.    M1 := 0;                                            { Turn Mouse Off }
  92.    mouse(M1,M2,M3,M4);
  93. END.
  94.  
  95. Reference Table
  96.   M1 M2 M3 M4
  97.   1  0  0  0   = Turn Mouse on with cursor.
  98.   2  0  0  0   = Turn Mouse Off.
  99.   3  ?  ?  ?   = To see if buttons are pressed.
  100.                   Test registers with logical AND   (M2 is BX register)
  101.                   M2 and 1 = Left Button
  102.                   M2 and 2 = Right Button
  103.                   M2 and 3 = Left and Right Buttons
  104.                   M2 and 4 = Middle Button
  105.                   M2 and 5 = Left and Middle Buttons
  106.                   M2 and 6 = Right and Middle Buttons
  107.                   M2 and 7 = Left, Middle and Right Buttons
  108.  
  109.   3  0  X  Y  = Get Mouse Cursor position.
  110.                  M3 (CX) will return Mouse X coordinates. (0  =left wall)
  111.                  M4 (DX) will return Mouse Y coordinates. (632= rght wall)
  112.                  Divide by 8 and add 1 for Turbo Pascal XY position.
  113.  
  114.   4  0  X  Y  = Set Mouse Cursor position.
  115.                  M3 (CX) set for Mouse X coordinate.      (0  = left wall)
  116.                  M4 (DX) set for Mouse Y coordinate.      (632= rght wall)
  117.  
  118.   6  ?  0  0  = Mouse Button Release Status.             M2(BX)set if True
  119.  
  120.                           Assembly Language Example
  121. mov ax,0001   ; (M1 := 1)
  122. int 33h       ; Set Mouse cursor ON
  123. here:         ;
  124. mov ax,0003   ; (M1 := 3)
  125. int 33h       ; Test for mouse Keypress
  126. and bx,1      ; left button?
  127. jne lft       ;
  128. mov ax,0003   ;
  129. int 33h       ;
  130. and bx,2      ; right button?
  131. jne rht       ;
  132. mov ax,0003   ;
  133. int 33h       ;
  134. and bx,4      ; middle button?
  135. jne mid       ;
  136. jmp here      ; if not keep looping
  137. lft:          ;
  138. mov dx,lft_st ; address of string if left button
  139. jmp prnt      ;
  140. rht:          ;
  141. mov dx,rht_st ; address of string if right button
  142.